function* rangeHandler(
  start: number,
  end: number,
  step: number,
) {
  for (let i = start; i < end; i += step) {
    yield i
  }
}

export function range(): Generator<number, void, unknown>
export function range(
  end: number
): Generator<number, void, unknown>
export function range(
  start: number,
  end: number
): Generator<number, void, unknown>
export function range(
  start: number,
  end: number,
  step: number
): Generator<number, void, unknown>
export function* range(...args: number[]) {
  const l = args.length
  if (l === 1) {
    yield * rangeHandler(0, args[0]!, 1)
  }
  else if (l === 2) {
    yield * rangeHandler(args[0]!, args[1]!, 1)
  }
  else if (l === 3) {
    yield * rangeHandler(args[0]!, args[1]!, args[2]!)
  }
  else {
    yield * rangeHandler(0, 10, 1)
  }
}
